local LobbyScene = class("LobbyScene", PokerViewBase)
local CURRENT_MODULE_NAME = ...
--[[
	界面处理需要保证就算是错误数据也做到不崩溃
	在获取到数据的时候进行checkData操作
]]
function LobbyScene:onCreate(data) --传入数据
	self:initWithFilePath("lobbyscene",CURRENT_MODULE_NAME, true)
	self.node.bottombtn_list:setTouchEnabled(false); 
	self.node.bottombtn_list:setScale(display.width/1280);

	self:_initialize();
end

function LobbyScene:_initialize(  )
	self._imgGirl = self.node.stupid_girl;
	self._gameNode = self.node.game_node;
	self._btnBack = self.node.btn_back;
	self._bottomBarNode = self.node.bottom_bg;
	self._topBarNode = self.node.bg_top;
	self._bottomBtnList = self.node.bottombtn_list;
	self._btnAgent = self._bottomBtnList:getChildByName("btn_agent");
	self._btnShare = self._bottomBtnList:getChildByName("btn_share");
	self._btnNotice = self._bottomBtnList:getChildByName("btn_notice");
	self._btnHistory = self._bottomBtnList:getChildByName("btn_history");
	self._btnHelp = self._bottomBtnList:getChildByName("btn_help");
	self._btnSettings = self._bottomBtnList:getChildByName("btn_settings");
	self._btnShop = self.node.btn_shop;
	self._btnShop:addClickEventListener(handler(self, self._onBtnShopClicked));
	self._btnBack:addClickEventListener(handler(self, self._onBtnBackClicked));
	self._btnAgent:addClickEventListener(handler(self, self._onBtnAgentClicked));
	self._btnShare:addClickEventListener(handler(self, self._onBtnShareClicked));
	self._btnNotice:addClickEventListener(handler(self, self._onBtnNoticeClicked));
	self._btnHistory:addClickEventListener(handler(self, self._onBtnHistoryClicked));
	self._btnHelp:addClickEventListener(handler(self, self._onBtnHelpClicked));
	self._btnSettings:addClickEventListener(handler(self, self._onBtnSettingClicked));

	self._btnAddDiamond = self.node.btn_add_diamond;
	self._btnAddDiamond:addClickEventListener(handler(self, self._onBtnAddDiamondClicked));

	self._bgHeadSprite = self.node.bg_head_sprite;

	self._lblName = self.node.name;
	self._lblUserId = self.node.id_txt;
	self._lblDiamond = self.node.diamond_txt;

	self:_resizeComponents();
	self:_playEnterEffect();
end
---
 -- 根据比例缩放节点
 -- @DateTime 2017-10-30
 -- @return   [description]
 --
function LobbyScene:_resizeComponents(  )
	local scale = display.width / 1280;
	self._gameNode:setScale(scale);
	self._imgGirl:setScale(scale);
	self._bottomBtnList:setScale(scale);
	self._topBarNode:setScale(scale);
	self._btnShop:setScale(scale);
end
---
 -- 播放渐显动画
 -- @DateTime 2017-10-30
 -- @return   [description]
 --
function LobbyScene:_playEnterEffect(  )
	local topBarNode = self.node.bg_top;
	local bottomBarNode = self.node.bottom_bg;
	local girlNode = self.node.stupid_girl;
	local gameNode = self.node.game_node;

	local function doActions(node, startPoint, endPoint)
		node:setOpacity(0);
		local ac1 = cc.MoveBy:create(0, startPoint);
		local ac2 = cc.MoveBy:create(0.40, endPoint);
		local ac3 = cc.FadeIn:create(0.40);

		local seq = cc.Sequence:create(ac1, cc.Spawn:create(ac2, ac3));
		transition.execute(node, seq);
	end

	doActions(girlNode, cc.p(-255, 0), cc.p(255, 0));
	doActions(gameNode, cc.p(400, 0), cc.p(-400, 0));
	doActions(bottomBarNode, cc.p(0, -65), cc.p(0, 65));
	doActions(topBarNode, cc.p(0, 50), cc.p(0, -50));
end
---
 -- 更新玩家信息
 -- @DateTime 2017-10-30
 -- @param    info 
 -- @return    [description]
 --
function LobbyScene:updateUserInfo(info)
	local playerInfo = info["gameplayer" .. SocketConfig.GAME_ID]
	self._lblName:setString(string.SubPlayerName(info.name, 1, 10));
	self._lblUserId:setString("ID:"..playerInfo.playerIndex);
	-- self.node.coin_txt:setString(playerInfo.gold);
	self._lblDiamond:setString(playerInfo.diamond)
	if info.photo == "headImg" then
		info.photo = self.res_base .. "/default_head.png";
	end
    self:loadHeadImage(info.photo);
end
---
 -- 加载头像
 -- @DateTime 2017-11-17
 -- @param    imgUrl [description]
 -- @return    [description]
 --
function LobbyScene:loadHeadImage( imgUrl )
	local maskUrl = self.res_base .. "/head_border.png";
 	local sprite = ImageUtils.downloadHeadImage(imgUrl, maskUrl, self._bgHeadSprite, 0.88);
 	local posX, posY = sprite:getPosition();
 	sprite:setPosition(cc.p(posX, posY + 1));
end

---
 -- 公告按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnNoticeClicked()
	SoundMgr.ClickButton();
	self.part:noticeClick()
end
---
 -- 玩法按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnHelpClicked()
	SoundMgr.ClickButton();
	self.part:helpClick()
end
---
 -- 战绩按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnHistoryClicked()
	SoundMgr.ClickButton();
	self.part:recordClick()
end
---
 -- 设置按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnSettingClicked()
	SoundMgr.ClickButton();
	self.part:settingsClick()
end
---
 -- 分享按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnShareClicked()
	-- body
	SoundMgr.ClickButton();
	self.part:reqShare();
end
---
 -- 代理按钮点击事件
 -- @DateTime 2017-10-19
 -- @param     [description]
 -- @return    [description]
 --
function LobbyScene:_onBtnAgentClicked( ... )
	self.part:agentClick()
end
---
 -- 返回合集大厅按钮点击事件
 -- @DateTime 2017-10-19
 -- @return   [description]
 --
function LobbyScene:_onBtnBackClicked()
	--如果是开房界面， 先返回选择界面
	if self.node.choiceType == "type_create_join" then
		self.part:changeChoiceNode("type_vip_match")
		return
	end
	self.part:returnLobby()
end
---
 -- 头像点击事件
 -- @DateTime 2017-11-13
 --
function LobbyScene:HeadClick()
	-- SoundMgr.ClickButton();
	-- self.part:headClick()
end
---
 -- 点击加钻按钮事件
 -- @DateTime 2017-11-14
 -- @return   [description]
 --
function LobbyScene:_onBtnAddDiamondClicked()
	SoundMgr.ClickButton();
	self.part:reqShopData();
end
---
 -- 创建房间事件
 -- @DateTime 2017-11-14
 --
function LobbyScene:CreateVipGameClick()
	SoundMgr.ClickButton();
	self.part:createVipGameClick()
end
---
 -- 加入房间事件
 -- @DateTime 2017-11-14
 --
function LobbyScene:AddGameClick()
	SoundMgr.ClickButton();
	self.part:requestStartGameClick();
end
---
 -- 创建金条场
 -- @DateTime 2017-11-14
 --
function LobbyScene:CreateGoldGameClick()
	-- SoundMgr.ClickButton();
	-- self.part:createGoldGameClick()
end

function LobbyScene:_onBtnShopClicked()
	SoundMgr.ClickButton();
	self.part:reqShopData();
end

function LobbyScene:backEvent()
	-- body
	self.part:backEvent()
end

function LobbyScene:getBroadcastNode(  )
	return self._broadcastNode;
end

return LobbyScene;

